package com.it.doudizhu2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class PokerGame {

    //牌盒Map
    //此时我们只要把牌跟序号产生对应关系就可以了，不需要按照顺序存储，HashMap的效率更高。
    static HashMap<Integer, String> hm = new HashMap<>();
    static ArrayList<Integer> list = new ArrayList<Integer>();

    static{
        String[] color = {"♦","♣","♥","♠"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //局部变量serialNumber
        int serialNumber = 1;
        for(String n : number){
            for(String c : color){
                hm.put(serialNumber,c+n);
                list.add(serialNumber);
                serialNumber++;
            }
        }
        hm.put(serialNumber,"小王");
        list.add(serialNumber);
        serialNumber++;
        hm.put(serialNumber,"大王");
        list.add(serialNumber);
        //System.out.println(hm);
    }
    public  PokerGame() {
        //洗牌
        Collections.shuffle(list);

        //发牌TreeSet自动排序
        TreeSet<Integer> lord = new TreeSet<>();
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();

        for(int i = 0; i < list.size(); i++){
            int serialNumber = list.get(i);

            if(i<=2){
                lord.add(serialNumber);
                continue;
            }

            if(i%3 == 0){
                player1.add(serialNumber);
            }else if(i%3 == 1){
                player2.add(serialNumber);
            }else{
                player3.add(serialNumber);
            }
        }

        //看牌
        lookPoker("底牌",lord);
        lookPoker("小周",player1);
        lookPoker("小肖",player2);
        lookPoker("小王",player3);



    }

    public void lookPoker(String name,TreeSet<Integer> ts){
        System.out.print(name+":");
        //b遍历TreeSet集合得到每一个序号，再拿着序号到Map集合中去找真正的牌
        for(int serialNumber : ts){
            String poker = hm.get(serialNumber);
            System.out.print(poker+" ");
        }
        System.out.println();
    }
}
